import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ColorChanger extends JFrame {
    private JPanel topPanel;

    public ColorChanger() {
        super("颜色更改器");
        setSize(400, 400);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        topPanel = new JPanel();
        topPanel.setBackground(Color.WHITE);

        JButton redButton = new JButton("红色");
        redButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                topPanel.setBackground(Color.RED);
            }
        });

        JButton yellowButton = new JButton("黄色");
        yellowButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                topPanel.setBackground(Color.YELLOW);
            }
        });

        JButton blueButton = new JButton("蓝色");
        blueButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                topPanel.setBackground(Color.BLUE);
            }
        });

        JPanel buttonPanel = new JPanel();
        buttonPanel.add(redButton);
        buttonPanel.add(yellowButton);
        buttonPanel.add(blueButton);

        Container content = getContentPane();
        content.setLayout(new BorderLayout());
        content.add(topPanel, BorderLayout.CENTER);
        content.add(buttonPanel, BorderLayout.SOUTH);
    }

    public static void main(String[] args) {
        ColorChanger frame = new ColorChanger();
        frame.setVisible(true);
    }
}
